import 'package:flutter/material.dart';

///-----------------------------------------------------------------------------
///打印生命周期的控件
class LifecycleWidget extends StatefulWidget {
  const LifecycleWidget({super.key});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return LifecycleState(title: "Simple View");
  }
}

class LifecycleState extends State<LifecycleWidget> {
  final String title;
  int _counter = 0;

  LifecycleState({required this.title});

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    print("LifecycleState >> build ");
    return Center(
      child: Column(
        children: [
          Text(_counter.toString()),
          TextButton(
            child: Text(title),
            onPressed: () {
              _incrementCounter();
            },
          ),
        ],
      ),
    );
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    print("LifecycleState >> didChangeDependencies ");
  }

  @override
  void didUpdateWidget(covariant LifecycleWidget oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);

    print("LifecycleState >> didUpdateWidget ");
  }

  @override
  void deactivate() {
    super.deactivate();
    print("LifecycleState >> deactivate");
  }

  @override
  void dispose() {
    super.dispose();
    print("LifecycleState >> dispose");
  }

  @override
  void reassemble() {
    super.reassemble();
    print("LifecycleState >> reassemble");
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    print("LifecycleState >> initState");
  }
}
